package com.example.classconnect;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class User implements Parcelable{
        
        private String id;
        private String fName;
        private String lName;
        private String email;
        private String pwd;
        private String description = "You haven't edited your information!";
        private String hobbies = "You haven't edited your hobbies!";
        private String clubs = "You haven't edited your clubs!";
        private String highschool = "You haven't edited your highschool!";
        private String living = "You haven't edited your living status!";
        private String classes = "noClasses";
        private String friends = "noFriends";
        //private List<User> myFriends;
        
        public User(){
        }
        public final void setfName(String name){
                fName = name;
        }
        public final void setlName(String name){
                lName = name;
        }
        public void setEmail(String mail){
                email = mail;
        }
        public void setPassword(String password){
                pwd = password;
        }
        public void setDescription(String desc){
        	if(!desc.matches("")){
        	description = desc;
        	}
        }
        public void setHobbies(String hob){
        	if(!hob.matches("")){
        	hobbies = hob;
        	}
        }
        public void setClubs(String club){
        	if(!club.matches("")){
        	clubs = club;
        	}
        }
        public void setHS(String hs){
        	if(!hs.matches("")){
        	highschool = hs;
        	}
        }
        public void setLiving(String live){
        	if(!live.matches("")){
        		living = live;
        	}
        }
        public void addFriend(String friend){
        	if(!friend.matches("")){
        	if (friends.matches("noFriends")){
        		friends = friend.concat(";");
        	} else{
        		friends = new StringBuilder().append(friends).append(friend).append(";").toString();
        	}
        	}
        }
        public void addClass(String Class){
        	if(!Class.matches("")){
        	if(classes.matches("noClasses")){
        		classes = Class.concat(";");
        	} else{
        		classes = new StringBuilder().append(classes).append(Class).append(";").toString();
        	}
        	}
        }
        
        /*public void addFriend(User friend){
                myFriends.add(friend);
        }*/
        public String getId(){
                return id;
        }
        public String getfName(){
                return fName;
        }
        public String getlName(){
                return lName;
        }
        public String getFullName(){
                return new StringBuilder().append(fName).append(" ").append(lName).toString();
        }
        public String getEmail(){
                return email;
        }
        public String getPassword(){
                return pwd;
        }
        public String getDescription(){
        		return description;
        }
        public String getHobbies(){
        		return hobbies;
        }
        public String getClubs(){
        		return clubs;
        }
        public String getHS(){
        		return highschool;
        }
        public String getLiving(){
        		return living;
        }
        public ArrayList<String> getFriendsList(){
                ArrayList<String> temp = new ArrayList<String>();
                char[] Temp = friends.toCharArray();
                String str = "Friend: ";
                if (friends.matches("noFriends")){
                	temp.add(friends);
                	return temp;
                } else{
                	for(int i = 0;i < Temp.length; i++){
                		if(Temp[i] == ';'){
                			temp.add(str);
                			str = "Friend: ";
                		}
                		else{
                			str = new StringBuilder().append(str).append(Temp[i]).toString();
                		} 
                	}
                	return temp;
                }
        }
        public ArrayList<String> getClassList(){
            ArrayList<String> temp = new ArrayList<String>();
            char[] Temp = classes.toCharArray();
            String str = "Class: ";
            if (classes.matches("noClasses")){
            	temp.add(classes);
            	return temp;
            } else{
            	for(int i = 0;i < Temp.length; i++){
            		if(Temp[i] == ';'){
            			temp.add(str);
            			str = "Class: ";
            		}
            		else{
            			str = new StringBuilder().append(str).append(Temp[i]).toString();
            		} 
            	}
            	return temp;
            }
    }
		@Override
		public int describeContents() {
			// TODO Auto-generated method stub
			return 0;
		}
		@Override
		public void writeToParcel(Parcel Dest, int arg1) {
			// TODO Auto-generated method stub
			Dest.writeString(id);
			Dest.writeString(fName);
			Dest.writeString(lName);
			Dest.writeString(email);
			Dest.writeString(pwd);
			Dest.writeString(description);
			Dest.writeString(hobbies);
			Dest.writeString(clubs);
			Dest.writeString(highschool);
			Dest.writeString(living);
			Dest.writeString(classes);
			Dest.writeString(friends);
		}
		public User(Parcel in)
	    {
	        this.id = in.readString();
	        this.fName = in.readString();
	        this.lName = in.readString();
	        this.email = in.readString();
	        this.pwd = in.readString();
	        this.description = in.readString();
	        this.hobbies = in.readString();
	        this.clubs = in.readString();
	        this.highschool = in.readString();
	        this.living = in.readString();
	        this.classes = in.readString();
	        this.friends = in.readString();
	    }
		@SuppressWarnings({ "unchecked", "rawtypes" })
	    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
	        public User createFromParcel(Parcel in)
	        {
	            return new User(in);
	        }
	 
	        public User[] newArray(int size)
	        {
	            return new User[size];
	        }
	    };
}